package org.zachary.prosocialbehaviorservice.interfaces;


import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import org.zachary.prosocialbehaviorservice.application.UserActivityService;
import org.zachary.prosocialbehaviorservice.application.command.JoinExitActivityCommand;
import org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity_user.UserJoinActivityDTO;
import org.zachary.prosocialbehaviorservice.infrastructure.utils.Result;

import java.util.List;
@Api(tags = "亲社会行为模块——用户-活动模块")
@RestController
@RequestMapping("/user_activity")
public class UserActivityController {
    private final UserActivityService userActivityService;

    public UserActivityController(UserActivityService userActivityService) {
        this.userActivityService = userActivityService;
    }

    @PostMapping("/join")
    public Result<String> joinActivity(@RequestBody JoinExitActivityCommand command){
        userActivityService.join(command);
        return Result.success("参与成功");
    }
    @PostMapping("/exit")
    public Result<String> exitActivity(@RequestBody JoinExitActivityCommand command){
        System.out.println(command.toString());
        userActivityService.exit(command.userId(),command.itemId());
        return Result.success("退出成功");
    }
    @GetMapping("/list")
    public Result<List<UserJoinActivityDTO>> getActivityList(@RequestParam Integer userId){
        List<UserJoinActivityDTO> list = userActivityService.list(userId);
        return Result.success(list);
    }

    @PostMapping("/finish")
    public Result<String> finishedActivityItem(@RequestBody JoinExitActivityCommand command){
        userActivityService.finishedItem(command);
        return Result.success("用户分更新已成功");
    }
}
